<template>
  <basic-crud
    :option="option"
    ref="basicCrudRef"
    :apiAddParams="apiAddParams"
    :before-close="handleBeforeClose"
  >
    <template #menu="{ row }">
      <el-button link type="primary" @click="handleAddSon(row)" icon="Plus"
        >新增下级</el-button
      >
    </template>
  </basic-crud>
</template>

<script setup>
import { trueFalseDic } from '@/config/enum.js'
const option = ref({
  viewBtn: true,
  menuWidth: 340,
  isTableTree: true,
  addBtn: true,
  rowKey: 'id',
  column: [
    {
      label: '楼栋名称',
      prop: 'name',
      minWidth: 200,
      search: true,
      rules: [{ required: true, message: '楼栋名称不能为空' }],
    },
    {
      label: '建筑类型',
      type: 'select',
      prop: 'buildType',
      dicCode: 'buildingType',
      search: true,
      minWidth: 120,
      rules: [{ required: true, message: '建筑类型不能为空' }],
    },
    {
      label: '管理部门',
      prop: 'manageDeptName', //用于展示的字段，一般为参照的名称
      component: 'BasicCrudTableSelect',
      dataType: 'dept', //表示使用组件自定义的内部参照
      comProps: {
        saveFieldMap: { manageDeptName: 'name', manageDept: 'id' },
      },
      minWidth: 120,
      rules: [{ required: true, message: '管理部门不能为空' }],
    },
    {
      label: '左上角的位置',
      prop: 'leftGps',
      minWidth: 120,
    },
    {
      label: '右上角的位置',
      prop: 'rightGps',
      minWidth: 120,
    },
    {
      label: '左下方的位置',
      prop: 'leftBottomGps',
      minWidth: 120,
    },
    {
      label: '右下方的位置',
      prop: 'rightBottomGps',
      minWidth: 120,
    },
    {
      label: '长度',
      prop: 'widthD',
      type: 'number',
      minWidth: 100,
    },
    {
      label: '高度',
      prop: 'heightD',
      type: 'number',
      minWidth: 100,
    },
    {
      label: '地图建筑物主键',
      prop: 'bindMapId',
      minWidth: 150,
    },
    {
      label: '地图模型主键',
      prop: 'mapModel',
      minWidth: 150,
    },
    {
      label: '楼层排序号',
      prop: 'levelSep',
      type: 'number',
      minWidth: 120,
    },
    {
      label: '海拔',
      prop: 'elevation',
      type: 'number',
      minWidth: 120,
    },
    {
      label: '单层',
      prop: 'preHeight',
      type: 'number',
      minWidth: 120,
    },
    {
      label: '指定存放物料',
      prop: 'designateMaterial',
      value: 'false',
      type: 'switch',
      dicData: trueFalseDic,
      minWidth: 120,
    },
    {
      label: '描述',
      type: 'textarea',
      prop: 'des',
      span: 24,
      minWidth: 200,
    },
  ],
})
const apiAddParams = reactive({ parentId: undefined })
const basicCrudRef = ref()
const handleAddSon = (row) => {
  apiAddParams.parentId = row.id
  basicCrudRef.value.crudRef.rowAdd()
}
// 关闭弹窗前清空apiAddParams数据
const handleBeforeClose = (done) => {
  apiAddParams.parentId = undefined
  done()
}
</script>

<style lang="scss" scoped></style>
